﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ETOrePriceCalc
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public List<Mineral> MineralList;
        public Dictionary<string, int> SolarSytemList;
		public ApiParser parser;
		private bool setup;
		public MainWindow()
		{
			InitializeComponent();
			parser = new ApiParser("cyril audeles", 10000002, 0);
			MineralList = setupMineralList();
            SolarSytemList = setupSolarsystemList();

            dgMinerals.ItemsSource = MineralList;
            comboBox13.ItemsSource = SolarSytemList.Keys;
		}

		/// <summary>
		/// fills the mineral list with all the required minerals
		/// </summary>
		/// <returns>returns the filled list</returns>
		private List<Mineral> setupMineralList()
		{
			List<Mineral> retval = new List<Mineral>();

			//all minerals to add
			#region minerals adding
			retval.Add(new Mineral("Veldspar"));
			retval.Add(new Mineral("Concentrated Veldspar"));
			retval.Add(new Mineral("Dense Veldspar"));
			retval.Add(new Mineral("Scordite"));
			retval.Add(new Mineral("Condensed Scordite"));
			retval.Add(new Mineral("Massive Scordite"));
			retval.Add(new Mineral("Pyroxeres"));
			retval.Add(new Mineral("Solid Pyroxeres"));
			retval.Add(new Mineral("Viscous Pyroxeres"));
			retval.Add(new Mineral("Plagioclase"));
			retval.Add(new Mineral("Azure Plagioclase"));
			retval.Add(new Mineral("Rich Plagioclase"));
			retval.Add(new Mineral("Omber"));
			retval.Add(new Mineral("Silvery Omber"));
			retval.Add(new Mineral("Golden Omber"));
			retval.Add(new Mineral("Kernite"));
			retval.Add(new Mineral("Luminous Kernite"));
			retval.Add(new Mineral("Fiery Kernite"));
			retval.Add(new Mineral("Jaspet"));
			retval.Add(new Mineral("Pure Jaspet"));
			retval.Add(new Mineral("Pristine Jaspet"));
			retval.Add(new Mineral("Hemorphite"));
			retval.Add(new Mineral("Vivid Hemorphite"));
			retval.Add(new Mineral("Radiant Hemorphite" ));
			retval.Add(new Mineral("Hedbergite"));
			retval.Add(new Mineral("Vitric Hedbergite"));
			retval.Add(new Mineral("Glazed Hedbergite" ));
			retval.Add(new Mineral("Gneiss"));
			retval.Add(new Mineral("Iridescent Gneiss")); 
			retval.Add(new Mineral("Prismatic Gneiss"));
			retval.Add(new Mineral("Dark Ochre"));
			retval.Add(new Mineral("Onyx Ochre"));
			retval.Add(new Mineral("Obsidian Ochre"));
			retval.Add(new Mineral("Crokite"));
			retval.Add(new Mineral("Sharp Crokite"));
			retval.Add(new Mineral("Crystalline Crokite"));
			retval.Add(new Mineral("Spodumain"));
			retval.Add(new Mineral("Bright Spodumain"));
			retval.Add(new Mineral("Gleaming Spodumain"));
			retval.Add(new Mineral("Bistot"));
			retval.Add(new Mineral("Triclinic Bistot"));
			retval.Add(new Mineral("Monoclinic Bistot"));
			retval.Add(new Mineral("Arkonor"));
			retval.Add(new Mineral("Crimson Arkonor"));
			retval.Add(new Mineral("Prime Arkonor"));
			retval.Add(new Mineral("Mercoxit"));
			retval.Add(new Mineral("Magma Mercoxit"));
			retval.Add(new Mineral("Vitreous Mercoxit"));
			#endregion


			return retval;
		}

        private Dictionary<string,int> setupSolarsystemList()
        {
            Dictionary<string, int> retval = new Dictionary<string, int>();

            retval.Add("Abagawa", 30000147);
            retval.Add("Ahtulaima", 30000125);
            retval.Add("Airaken", 30000185);
            retval.Add("Airmia", 30000166);
            retval.Add("Akkilen", 30000178);
            retval.Add("Akkio", 30000200);
            retval.Add("Akora", 30000163);
            retval.Add("Ansila", 30000132);
            retval.Add("Aokannitoh", 30021407);
            retval.Add("Eruka", 30000203);
            retval.Add("Eskunen", 30000137);
            retval.Add("Friggi", 30000168);
            retval.Add("Fuskunen", 30000199);
            retval.Add("Gekutami", 30000149);
            retval.Add("Geras", 30000126);
            retval.Add("Hampinen", 30000152);
            retval.Add("Hentogaira", 30000188);
            retval.Add("Hirtamon", 30000133);
            retval.Add("Hurtoken", 30000150);
            retval.Add("Hykkota", 30000134);
            retval.Add("Ihakana", 30000169);
            retval.Add("Ikami", 30000159);
            retval.Add("Ikuchi", 30000138);
            retval.Add("Inaya", 30000182);
            retval.Add("Ishisomo", 30000165);
            retval.Add("Itamo", 30000119);
            retval.Add("Jakanerva", 30000148);
            retval.Add("Jatate", 30000121);
            retval.Add("Jita", 30000142);
            retval.Add("Josameto", 30000156);
            retval.Add("Keikaken", 30000176);
            retval.Add("Kiainti", 30000189);
            retval.Add("Kisogo", 30000141);
            retval.Add("Korsiki", 30000181);
            retval.Add("Kylmabe", 30000124);
            retval.Add("Liekuri", 30000154);
            retval.Add("Mahtista", 30000122);
            retval.Add("Mastakomon", 30000202);
            retval.Add("Maurasi", 30000140);
            retval.Add("Messoya", 30000164);
            retval.Add("Mitsolen", 30000120);
            retval.Add("New Caldari", 30000145);
            retval.Add("Niyabainen", 30000143);
            retval.Add("Nomaa", 30000131);
            retval.Add("Nuken", 30000183);
            retval.Add("Obanen", 30000155);
            retval.Add("Obe", 30000205);
            retval.Add("Ohkunen", 30000204);
            retval.Add("Ohmahailen", 30000136);
            retval.Add("Oijanen", 30000186);
            retval.Add("Olo", 30000158);
            retval.Add("Onuse", 30000174);
            retval.Add("Osmon", 30000180);
            retval.Add("Otanuomi", 30000192);
            retval.Add("Otela", 30000157);
            retval.Add("Otitoh", 30000171);
            retval.Add("Otomainen", 30000172);
            retval.Add("Otosela", 30000196);
            retval.Add("Otsela", 30000194);
            retval.Add("Outuni", 30000135);
            retval.Add("Paala", 30000198);
            retval.Add("Perimeter", 30000144);
            retval.Add("Poinen", 30000153);
            retval.Add("Purjola", 30000161);
            retval.Add("Reisen", 30000160);
            retval.Add("Saisio", 30000146);
            retval.Add("Sakenta", 30010141);
            retval.Add("Sankkikainen", 30000167);
            retval.Add("Senda", 30020141);
            retval.Add("Shihuken", 30000130);
            retval.Add("Silen", 30000179);
            retval.Add("Sirseshin", 30000127);
            retval.Add("Soshin", 30000175);
            retval.Add("Tasti", 30000195);
            retval.Add("Tuuriainas", 30000128);
            retval.Add("Uchoshi", 30000201);
            retval.Add("Uemon", 30000197);
            retval.Add("Uitra", 30030141);
            retval.Add("Ukkalen", 30000177);
            retval.Add("Uminas", 30000184);
            retval.Add("Unpas", 30000129);
            retval.Add("Uoyonen", 30000151);
            retval.Add("Urlen", 30000139);
            retval.Add("Vaankalen", 30000123);
            retval.Add("Vahnuomi", 30000170);
            retval.Add("Vasala", 30000190);
            retval.Add("Vattuolen", 30000173);
            retval.Add("Vousiakho", 30000193);
            retval.Add("Walvalin", 30000191);
            retval.Add("Wirashoda", 30000206);
            retval.Add("Wuos", 30000187);
            retval.Add("Adallier", 30015305);
            retval.Add("Aidart", 30005307);
            retval.Add("Alenia", 30005302);
            retval.Add("Alentene", 30005304);
            retval.Add("Amodenia", 30005329);
            retval.Add("Amygnon", 30005311);
            retval.Add("Annelle", 30005326);
            retval.Add("Ansalle", 30005309);
            retval.Add("Arraron", 30005330);
            retval.Add("Channace", 30025305);
            retval.Add("Chantrousse", 30005331);
            retval.Add("Chesiette", 30005327);
            retval.Add("Cistuvaert", 30005305);
            retval.Add("Clacille", 30035305);
            retval.Add("Claulenne", 30005324);
            retval.Add("Clellinon", 30045305);
            retval.Add("Costolle", 30005298);
            retval.Add("Ekuenbiron", 30005317);
            retval.Add("Eletta", 30005315);
            retval.Add("Ellmay", 30005313);
            retval.Add("Gisleres", 30005312);
            retval.Add("Hevrice", 30005320);
            retval.Add("Jovainnon", 30005321);
            retval.Add("Jufvitte", 30005308);
            retval.Add("Loes", 30005300);
            retval.Add("Luse", 30005316);
            retval.Add("Masalle", 30005325);
            retval.Add("Melmaniel", 30005296);
            retval.Add("Merolles", 30005303);
            retval.Add("Muetralle", 30005299);
            retval.Add("Murethand", 30005295);
            retval.Add("Osmomonne", 30005332);
            retval.Add("Ouelletta", 30005297);
            retval.Add("Raneilles", 30005319);
            retval.Add("Reblier", 30005328);
            retval.Add("Scheenins", 30005310);
            retval.Add("Scolluzer", 30005322);
            retval.Add("Sortet", 30005323);
            retval.Add("Stou", 30005333);
            retval.Add("Theruesse", 30005314);
            retval.Add("Tierijev", 30005334);
            retval.Add("Tourier", 30005301);
            retval.Add("Vaere", 30005306);
            retval.Add("Vay", 30005318);

            return retval;
        }

		/// <summary>
		/// changes the stock of mineral to amount
		/// </summary>
		/// <param name="mineral">name of the mineral</param>
		/// <param name="amount">new stock of mineral</param>
        public void setStock(string mineral, long amount)
		{
			//find the mineral class
			Mineral target = null;
			foreach (Mineral m in MineralList)
			{
				if (m.Name == mineral)
				{
					target = m;
					break;
				}
			}

			//set the stock of the mineral to the amount
			if (target != null)
				target.Stock = amount;
		}

		/// <summary>
		/// gets the current stock of the mineral
		/// </summary>
		/// <param name="mineral">name of the mineral to lookup</param>
		/// <returns>return the current stock of mineral</returns>
		public long getStock(string mineral)
		{
			foreach (Mineral m in MineralList)
			{
				if (m.Name == mineral)
					return m.Stock;
			}
			return 0;
		}

		private void btRefresh_Click(object sender, RoutedEventArgs e)
		{
            if (comboBox13.Text == "")
            {
                MessageBox.Show("Please select a solar system.");
                return;
            }
            btRefresh.Cursor = Cursors.Wait;
            parser.SolarSystem = SolarSytemList[comboBox13.Text];

			parser.GetPrices();
			parser.SetPrices(MineralList);
            btRefresh.Cursor = Cursors.Arrow;
            this.Focus();
		}

		private void btTotal_Click(object sender, RoutedEventArgs e)
		{
			double total = 0;

			foreach (Mineral m in MineralList)
			{
				total += m.Value;
			}

			tbTotal.Text = total.ToString();
		}

		private void btTest_Click(object sender, RoutedEventArgs e)
		{
			TestWindow test = new TestWindow(MineralList);
            test.ShowDialog();
		}
	}
}
